//
//  KamiTableViewCell.m
//  HengYouCai
//
//  Created by lwj on 2017/9/29.
//  Copyright © 2017年 lwj. All rights reserved.
//

#import "KamiTableViewCell.h"

@implementation KamiTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    UIButton * cdKeyCopyBtn = [self viewWithTag:1003];
    cdKeyCopyBtn.layer.cornerRadius = cdKeyCopyBtn.frame.size.height/2;

}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
- (void)setModel:(CDKeyModel *)model
{
    
    //    UIImageView * bgView = [self viewWithTag:1004];
    UILabel * typeLab = [self viewWithTag:1001];
    typeLab.text = model.cdkeyTypeName;
    
    UIButton * cdKeyCopyBtn = [self viewWithTag:1003];
    [cdKeyCopyBtn setTitle:@"    复制卡密    " forState:UIControlStateNormal];
    
    UILabel * cdkeyLab = [self viewWithTag:1005];
    cdkeyLab.text = [NSString stringWithFormat:@"卡密：%@",model.cdkey];
    
    //    "grant_time" = "2018-02-09 09:04:19";
//    dateLab.text = [NSString stringWithFormat:@"%@领取",model.grant_time];
    UILabel * contentLab = [self viewWithTag:1002];
    //    cdkey = "4B96-BB81";
//    [cdKeyCopyBtn setAttributedTitle:[[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"卡密  %@  复制",model.cdkey] attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:13],NSForegroundColorAttributeName: [UIColor whiteColor]}] forState:UIControlStateNormal];
    //    cdkeyType = "-1";
    NSString *typeStr = @"";
    NSMutableAttributedString *valueAttriStr = [[NSMutableAttributedString alloc] initWithString:@""];
    if ([model.cdkeyType isEqualToString:@"-1"]) {//27pt fontSize 元 即京东卡
        typeStr = @"￥";
        [valueAttriStr appendAttributedString:[[NSAttributedString alloc] initWithString:typeStr attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:13]}]];
        [valueAttriStr appendAttributedString:[[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"%zd",model.cdkeyDenomination.integerValue] attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:35]}]];
        [valueAttriStr appendAttributedString:[[NSAttributedString alloc] initWithString:@"元\n" attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:13]}]];
        [valueAttriStr appendAttributedString:[[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"获取日期：%@",model.grant_time] attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:12]}]];
        contentLab.attributedText = valueAttriStr;
        return;
    }else if ([model.cdkeyType isEqualToString:@"0"]) {
        typeStr = @"天";
    }else if ([model.cdkeyType isEqualToString:@"1"]) {
        typeStr = @"月";
    }else if ([model.cdkeyType isEqualToString:@"2"]) {
        typeStr = @"年";
    }    //    cdkeyTypeName = "\U4eac\U4e1c\U5361";
    [valueAttriStr appendAttributedString:[[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"%zd",model.cdkeyDenomination.integerValue] attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:24]}]];
            [valueAttriStr appendAttributedString:[[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@\n",typeStr] attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:13]}]];
    [valueAttriStr appendAttributedString:[[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"获取日期：%@",model.grant_time] attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:12]}]];
    contentLab.attributedText = valueAttriStr;
}
@end
